package com.xd.springboot.controller;

import com.xd.springboot.entity.User;
import com.xd.springboot.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/byName/{name}")
    public User getUserByName(@PathVariable String name)
    {
        return userService.getUserByName(name);
    }

    @RequestMapping("/getall")
    public List<User> getAll()
    {
        return userService.getAll();
    }

    @RequestMapping("/getuser/{id}")
    public  User getUser(@PathVariable Long id)
    {
        return userService.getUser(id);
    }

    @RequestMapping("/getuser/{id}/{name}")
    public  User getUser(@PathVariable Long id,@PathVariable String name)
    {
        return userService.getUser(id,name);
    }

    @PostMapping("/adduser")
    public  String addUser(@RequestBody User user) throws  Exception
    {
        if(null != user)
        {
            userService.insertUser(user);
            return "add user success";
        }else{
            return "add user false";
        }
    }

    @PostMapping("/adduser2")
    public  String addUser2(@RequestBody User user) throws  Exception
    {
        if(null != user)
        {
            userService.insertUser2(user);
            return "add user success";
        }else{
            return "add user false";
        }
    }

    @PostMapping("/adduser3")
    public  String addUser3(@RequestBody User user) throws  Exception
    {
        if(null != user)
        {
            userService.insertUser3(user);
            return "add user success";
        }else{
            return "add user false";
        }
    }

    @PostMapping("/adduser4")
    public  String addUser4(@RequestBody User user) throws  Exception
    {
        if(null != user)
        {
            userService.insertUser4(user);
            return "add user success";
        }else{
            return "add user false";
        }
    }
}
